package com.xnyzc.lhy.order.service.impl.common.pay;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xnyzc.lhy.common.component.convert.StringToDateConverter;
import com.xnyzc.lhy.common.component.convert.WxStringToDateConverter;
import com.xnyzc.lhy.common.exception.PangException;
import com.xnyzc.lhy.common.penum.EErrorCode;
import com.xnyzc.lhy.common.penum.carpool.EInvitationPayType;
import com.xnyzc.lhy.common.penum.carpool.EInvitationType;
import com.xnyzc.lhy.common.penum.order.EOrderNoType;
import com.xnyzc.lhy.common.penum.pay.EPayMoneyLock;
import com.xnyzc.lhy.common.penum.pay.EPayStatus;
import com.xnyzc.lhy.common.penum.pay.EPayType;
import com.xnyzc.lhy.common.penum.pay.ETransactionOrderNoType;
import com.xnyzc.lhy.common.penum.push.EJPushBalanceChangeType;
import com.xnyzc.lhy.common.penum.wallet.EDRecordType;
import com.xnyzc.lhy.common.penum.wallet.EIsTransaction;
import com.xnyzc.lhy.common.penum.wallet.ERecordType;
import com.xnyzc.lhy.common.util.CheckUtil;
import com.xnyzc.lhy.order.entity.order.OaCOrder;
import com.xnyzc.lhy.order.entity.order.OaCOrderApprovalOfficial;
import com.xnyzc.lhy.order.entity.order.OaCOrderPersonal;
import com.xnyzc.lhy.order.entity.order.OaCOrderPersonalOfficial;
import com.xnyzc.lhy.order.entity.user.wallet.OaCWallet;
import com.xnyzc.lhy.order.entity.user.wallet.OaCWalletRecord;
import com.xnyzc.lhy.order.entity.util.OrderUtil;
import com.xnyzc.lhy.order.mapper.order.OaCOrderApprovalOfficialMapper;
import com.xnyzc.lhy.order.mapper.order.OaCOrderPersonalMapper;
import com.xnyzc.lhy.order.mapper.order.OaCOrderPersonalOfficialMapper;
import com.xnyzc.lhy.order.mapper.user.wallet.OaCWalletMapper;
import com.xnyzc.lhy.order.mapper.user.wallet.OaCWalletRecordMapper;
import com.xnyzc.lhy.order.service.common.pay.IOaPaymentService;
import com.xnyzc.lhy.order.service.order.IOaCCostDetailsService;
import com.xnyzc.lhy.order.service.user.pay.IOaCUserPayService;
import com.xnyzc.lhy.order.util.service.JPushBalanceChangeUtilService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 支付回调业务处理
 * </p>
 *
 * @author 刘举
 * @since 2019-08-03
 */
@Slf4j
@Service
public class OaPaymentServiceImpl implements IOaPaymentService {

    @Autowired
    private OaCWalletMapper oaCWalletMapper;
    @Autowired
    private OaCWalletRecordMapper oaCWalletRecordMapper;
    @Autowired
    private OaCOrderPersonalMapper oaCOrderPersonalMapper;
    @Autowired
    private OaCOrderPersonalOfficialMapper oaCOrderPersonalOfficialMapper;
    @Autowired
    private OaCOrderApprovalOfficialMapper oaCOrderApprovalOfficialMapper;
    @Autowired
    private IOaCUserPayService iOaCUserPayService;
    @Autowired
    private JPushBalanceChangeUtilService jPushBalanceChangeUtilService;
    @Autowired
    private IOaCCostDetailsService iOaCCostDetailsService;

    /**
     * 支付宝回调业务逻辑处理
     *
     * @param payStatus    支付状态（0：交易关闭、1：交易成功）
     * @param orderNo      订单号
     * @param tradeNo      交易凭证号
     * @param totalAmount  总金额
     * @param gmtPayment   交易时间
     * @param passBackJson 回传参数
     * @param payType      支付类型（0：支付宝、1：微信）
     */
    @Override
    public void processAliPayNotify(Integer payStatus, String orderNo, String tradeNo, String totalAmount,
                                    String gmtPayment, JSONObject passBackJson, Integer payType) {

        if (CheckUtil.objIsEmpty(orderNo, tradeNo, totalAmount, gmtPayment, passBackJson)) {
            throw new PangException(EErrorCode.missingArg);
        }
        // 验证订单
        // 自费叫车或审批公务
        if (orderNo.contains(EOrderNoType.ZFJC.getType()) || orderNo.contains(EOrderNoType.SPGW.getType())){
            this.getZFJCOrSPGW(orderNo, totalAmount, payType, tradeNo, payStatus);
        }
        // 个人公务
        else if (orderNo.contains(EOrderNoType.GRGW.getType())){
            this.getGRGW(orderNo, totalAmount, payType, tradeNo, payStatus);
        }
        // 充值余额
        else if (orderNo.contains(EOrderNoType.CZYE.getType())){
            this.getCZYE(orderNo, tradeNo, gmtPayment, totalAmount, payStatus, payType);
        }
        // 非法订单号
        else {
            // TODO 退款
            throw PangException.create(EErrorCode.unOrderNo);
        }
    }

    /**
     * 封装自费叫车或审批公务
     * @param orderNo 订单号
     * @param totalAmount 总金额
     * @param payType 支付类型（0：支付宝、1：微信）
     * @param tradeNo 交易凭证号
     */
    private void getZFJCOrSPGW(String orderNo, String totalAmount, Integer payType, String tradeNo, Integer payStatus){
        BigDecimal zero = new BigDecimal(0);
        if (EPayStatus.payClose.getType().equals(payStatus)){
            throw PangException.create(EErrorCode.payFailure);
        }
        // 自费叫车
        com.xnyzc.lhy.order.entity.order.OaCOrderPersonal oaCOrderPersonal = null;
        // 审批公务
        OaCOrderApprovalOfficial oaCOrderApprovalOfficial = null;
        // 总金额
        BigDecimal totalFee;
        // 抽成费
        BigDecimal drawFee;
        Long userId;
        String tag;
        // 自费叫车
        if (orderNo.contains(EOrderNoType.ZFJC.getType())){
            // 订单
            oaCOrderPersonal = oaCOrderPersonalMapper.selectOne(
                    Wrappers.<OaCOrderPersonal>lambdaQuery()
                            .eq(com.xnyzc.lhy.order.entity.order.OaCOrder::getOrderNo, orderNo)
            );
            if (CheckUtil.objIsEmpty(oaCOrderPersonal)){
                throw PangException.create(EErrorCode.unOrder);
            }
            userId = oaCOrderPersonal.getUserId();
            tag = oaCOrderPersonal.getTag();
            // 总金额
            totalFee = oaCOrderPersonal.getTotalFee();
            drawFee = oaCOrderPersonal.getDrawFee();
        }
        // 审批公务
        else {
            // 订单
            oaCOrderApprovalOfficial = oaCOrderApprovalOfficialMapper.selectOne(
                    Wrappers.<OaCOrderApprovalOfficial>lambdaQuery()
                            .eq(OaCOrderApprovalOfficial::getOrderNo, orderNo)
            );
            if (CheckUtil.objIsEmpty(oaCOrderApprovalOfficial)){
                throw PangException.create(EErrorCode.unOrder);
            }
            userId = oaCOrderApprovalOfficial.getUserId();
            tag = oaCOrderApprovalOfficial.getTag();
            // 自费总金额
            totalFee = iOaCUserPayService.getSelfFee(orderNo, tag);
            drawFee = oaCOrderApprovalOfficial.getDrawFee();
        }
        // 用户钱包
        OaCWallet oaCWallet = oaCWalletMapper.selectOne(
                Wrappers.<OaCWallet>lambdaQuery()
                        .eq(OaCWallet::getUserId, userId)
                        .eq(OaCWallet::getTag, tag)
        );
        if (CheckUtil.objIsEmpty(oaCWallet)){
            throw PangException.create(EErrorCode.unWallet);
        }
        // 钱包余额
        BigDecimal walletBalance = oaCWallet.getWalletBalance();
        // 个人额度
        BigDecimal personalOfficialBalance = oaCWallet.getPersonalOfficialBalance();
        // 部门额度
        BigDecimal deptOfficialBalance = oaCWallet.getDeptOfficialBalance();
        Date date = new Date();
        // 更新钱包余额
        this.updateOaCWallet(oaCWallet, personalOfficialBalance, deptOfficialBalance, userId, date);
        // 三方额度
        BigDecimal otherMoney = new BigDecimal(totalAmount);
        // 余额消耗金额
        BigDecimal actualAmount = totalFee.subtract(otherMoney);
        if (walletBalance.compareTo(zero) != 0){
            // 插入余额消费记录
            iOaCUserPayService.insertOaCWalletRecord(userId, orderNo, actualAmount, zero, personalOfficialBalance, deptOfficialBalance, ERecordType.moneyDisbursement, tradeNo, date, tag, EIsTransaction.paySuccess);
        }
        // 自费叫车
        if (orderNo.contains(EOrderNoType.ZFJC.getType())){
            // 自费叫车回调业务处理
            this.callbackOaCOrderPersonal(userId, tag, payType, orderNo, tradeNo, otherMoney, personalOfficialBalance, deptOfficialBalance, drawFee, totalFee, oaCOrderPersonal);
        }
        // 审批公务
        else {
            // 审批回调业务处理
            this.callbackOaCOrderApprovalOfficial(userId, tag, payType, orderNo, tradeNo, otherMoney, personalOfficialBalance, deptOfficialBalance, drawFee, totalFee, oaCOrderApprovalOfficial);
        }
    }

    /**
     * 个人公务
     * @param orderNo 订单号
     * @param totalAmount 交易金额
     * @param payType 交易类型
     * @param tradeNo 交易凭证号
     */
    private void getGRGW(String orderNo, String totalAmount, Integer payType, String tradeNo, Integer payStatus){
        if (EPayStatus.payClose.getType().equals(payStatus)){
            throw PangException.create(EErrorCode.payFailure);
        }
        // 订单
        List<OaCOrderPersonalOfficial> oaCOrderPersonalOfficials = oaCOrderPersonalOfficialMapper.selectList(
                Wrappers.<OaCOrderPersonalOfficial>lambdaQuery()
                        .eq(OaCOrder::getOrderNo, orderNo)
        );
        if (oaCOrderPersonalOfficials.size() != 1){
            log.info(String.format("未查询订单号为 %s 的订单", orderNo));
            throw PangException.create(EErrorCode.unOrder);
        }
        OaCOrderPersonalOfficial oaCOrderPersonalOfficial = oaCOrderPersonalOfficials.get(0);
        String tag = oaCOrderPersonalOfficial.getTag();
        Long userId = oaCOrderPersonalOfficial.getUserId();
        // 总金额
        BigDecimal totalFee = oaCOrderPersonalOfficial.getTotalFee();
        // 抽成费
        BigDecimal drawFee = oaCOrderPersonalOfficial.getDrawFee();
        // 私用费用
        BigDecimal priFee = iOaCUserPayService.getSelfFee(orderNo, tag);
        // 公用费用
        BigDecimal pubFee = totalFee.subtract(priFee);
        // 用户钱包
        OaCWallet oaCWallet = oaCWalletMapper.selectOne(
                Wrappers.<OaCWallet>lambdaQuery()
                        .eq(OaCWallet::getUserId, userId)
                        .eq(OaCWallet::getTag, tag)
        );
        if (CheckUtil.objIsEmpty(oaCWallet)){
            throw PangException.create(EErrorCode.unWallet);
        }
        Date date = new Date();
        BigDecimal zero = new BigDecimal(0);
        // 余额
        BigDecimal walletBalance = oaCWallet.getWalletBalance();
        // 个人额度
        BigDecimal personalOfficialBalance = oaCWallet.getPersonalOfficialBalance();
        // 部门额度
        BigDecimal deptOfficialBalance = oaCWallet.getDeptOfficialBalance();
        // 计算剩余个人额度
        BigDecimal lastAmount = personalOfficialBalance.subtract(pubFee);
        // 插入钱包记录
        this.updateOaCWallet(oaCWallet, lastAmount, deptOfficialBalance, userId, date);
        if (walletBalance.compareTo(zero) != 0){
            // 插入余额钱包记录
            iOaCUserPayService.insertOaCWalletRecord(userId, orderNo, walletBalance, zero, personalOfficialBalance, deptOfficialBalance, ERecordType.moneyDisbursement, OrderUtil.transactionOrderNo(ETransactionOrderNoType.balancePay), date, tag, EIsTransaction.paySuccess);
        }
        // 额度
        iOaCUserPayService.insertOaCWalletRecord(userId, orderNo, pubFee, walletBalance, lastAmount, deptOfficialBalance, ERecordType.myDisbursement, OrderUtil.transactionOrderNo(ETransactionOrderNoType.personalBusiness), date, tag, EIsTransaction.paySuccess);
        // 三方额度
        BigDecimal otherMoney = new BigDecimal(totalAmount);
        // 代付
        OaCOrderPersonal personal = null;
        if (EInvitationType.personal.getValue().equals(oaCOrderPersonalOfficial.getInvitationType()) &&
                EInvitationPayType.invitePeoplePay.getValue().equals(oaCOrderPersonalOfficial.getInvitationPayType())){
            // 邀约拼车流水号
            String carpoolSerialNo = oaCOrderPersonalOfficial.getCarpoolSerialNo();
            // 被邀约人订单
            personal = iOaCCostDetailsService.getInvitationOaCOrderPersonal(tag, carpoolSerialNo);
            if (CheckUtil.objIsNotEmpty(personal)){
                drawFee = drawFee.add(iOaCCostDetailsService.bigDecimalIsNull(personal.getDrawFee()));
            }
        }
        // 支付宝
        if (payType.equals(0)){
            iOaCUserPayService.insertOaCWalletRecord(userId, orderNo, otherMoney, zero, personalOfficialBalance, deptOfficialBalance, ERecordType.alipayDisbursement, tradeNo, date, tag, EIsTransaction.paySuccess);
            // 更新司机钱包
            iOaCUserPayService.updateDriverWallet(oaCOrderPersonalOfficial.getDriverId(), userId, tag, drawFee, orderNo, EDRecordType.aliPayIncome, tradeNo);
            // 更新订单
            // 被邀人更新订单
            if (CheckUtil.objIsNotEmpty(personal)){
                BigDecimal total = iOaCCostDetailsService.bigDecimalIsNull(personal.getTotalFee());
                iOaCUserPayService.updateOaCOrderPersonal(personal, total, date, userId, EPayType.alipay);
            }
            iOaCUserPayService.updateOaCOrderPersonalOfficial(oaCOrderPersonalOfficial, totalFee, date, userId, EPayType.alipay);
        }
        // 微信
        else {
            iOaCUserPayService.insertOaCWalletRecord(userId, orderNo, otherMoney, zero, personalOfficialBalance, deptOfficialBalance, ERecordType.weChatDisbursement, tradeNo, date, tag, EIsTransaction.paySuccess);
            // 更新司机钱包
            iOaCUserPayService.updateDriverWallet(oaCOrderPersonalOfficial.getDriverId(), userId, tag, drawFee, orderNo, EDRecordType.weChatIncome, tradeNo);
            // 更新订单
            // 被邀人更新订单
            if (CheckUtil.objIsNotEmpty(personal)){
                BigDecimal total = iOaCCostDetailsService.bigDecimalIsNull(personal.getTotalFee());
                iOaCUserPayService.updateOaCOrderPersonal(personal, total, date, userId, EPayType.weChat);
            }
            iOaCUserPayService.updateOaCOrderPersonalOfficial(oaCOrderPersonalOfficial, totalFee, date, userId, EPayType.weChat);
        }
    }


    /**
     * 充值余额
     * @param payStatus    支付状态（0：交易关闭、1：交易成功）
     * @param orderNo      订单号
     * @param tradeNo      交易凭证号
     * @param totalAmount  总金额
     * @param gmtPayment   交易时间
     */
    private void getCZYE(String orderNo, String tradeNo, String gmtPayment, String totalAmount, Integer payStatus, Integer payTape){
        Date date = new Date();
        // 正式环境打开
        BigDecimal otherMoney = new BigDecimal(totalAmount);
        OaCWalletRecord oaCWalletRecord = oaCWalletRecordMapper.selectOne(
                Wrappers.<OaCWalletRecord>lambdaQuery()
                        .eq(OaCWalletRecord::getOrderNo, orderNo));
        if (CheckUtil.objIsEmpty(oaCWalletRecord)){
            throw PangException.create(EErrorCode.unOrder);
        }
        if (EPayStatus.paySuccess.getType().equals(payStatus)){
            // 正式环境放开
            BigDecimal lastBalance = oaCWalletRecord.getWalletBalance().add(otherMoney);
            oaCWalletRecord.setIsTransaction(EIsTransaction.paySuccess.getValue());
            oaCWalletRecord.setTransactionOrderNo(tradeNo);
            if (EPayType.alipay.getType().equals(payTape)){
                oaCWalletRecord.setTransactionTime(new StringToDateConverter().convert(gmtPayment));
            } else {
                oaCWalletRecord.setTransactionTime(new WxStringToDateConverter().convert(gmtPayment));
            }
            oaCWalletRecord.setWalletBalance(lastBalance);
            oaCWalletRecord.setUpdateTime(date);
            int i = oaCWalletRecordMapper.updateById(oaCWalletRecord);
            if (i != 1){
                log.info("更新用户钱包状态失败");
            }
            // 更新余额
            OaCWallet oaCWallet = oaCWalletMapper.selectOne(
                    Wrappers.<OaCWallet>lambdaQuery()
                            .eq(OaCWallet::getUserId, oaCWalletRecord.getUserId())
                            .eq(OaCWallet::getTag, oaCWalletRecord.getTag())
            );
            oaCWallet.setWalletBalance(lastBalance);
            oaCWallet.setUpdateTime(date);
            int j = oaCWalletMapper.updateById(oaCWallet);
            if (j != 1){
                log.info("更新用户钱包状态失败");
            }
        } else {
            oaCWalletRecord.setIsTransaction(EIsTransaction.payFailed.getValue());
            if (EPayType.weChat.getType().equals(payTape)){
                oaCWalletRecord.setTransactionTime(new WxStringToDateConverter().convert(gmtPayment));
            } else {
                oaCWalletRecord.setTransactionTime(new StringToDateConverter().convert(gmtPayment));
            }
            oaCWalletRecord.setTransactionOrderNo(tradeNo);
            oaCWalletRecord.setUpdateTime(date);
            int i = oaCWalletRecordMapper.updateById(oaCWalletRecord);
            if (i != 1){
                log.info("更新用户钱包状态失败");
            }
            // 极光推送 余额变更
            jPushBalanceChangeUtilService.passengerPush(
                    oaCWalletRecord.getUserId(),
                    oaCWalletRecord.getTag(),
                    EJPushBalanceChangeType.recharge.getValue(),
                    oaCWalletRecord.getRecordId(), otherMoney);
            throw PangException.create(EErrorCode.payFailure);
        }
    }

    /**
     * 更新钱包余额
     * @param oaCWallet 钱包实体
     * @param userId 用户id
     * @return
     */
    private void updateOaCWallet(OaCWallet oaCWallet, BigDecimal personalOfficialBalance, BigDecimal deptOfficialBalance, Long userId, Date date){
        // 获取锁
        Long version = oaCWalletMapper.selectById(oaCWallet.getWalletId()).getVersion();
        // 无论成功失败都需要解锁
        OaCWallet updateOaCWallet = new OaCWallet();
        updateOaCWallet.setWalletId(oaCWallet.getWalletId());
        updateOaCWallet.setVersion(version);
        updateOaCWallet.setUpdateUser(userId);
        if (CheckUtil.objIsNotEmpty(personalOfficialBalance)){
            updateOaCWallet.setPersonalOfficialBalance(personalOfficialBalance);
        }
        updateOaCWallet.setUpdateTime(date);
        updateOaCWallet.setWalletBalance(new BigDecimal(0));
        if (CheckUtil.objIsNotEmpty(deptOfficialBalance)){
            updateOaCWallet.setDeptOfficialBalance(deptOfficialBalance);
        }
        updateOaCWallet.setIsPersonalPay(EPayMoneyLock.yes.getType());
        updateOaCWallet.setIsBalancelPay(EPayMoneyLock.yes.getType());
        updateOaCWallet.setIsDeptPay(EPayMoneyLock.yes.getType());
        int i = oaCWalletMapper.updateById(updateOaCWallet);
        if (i != 1){
            // TODO 执行退款
            throw PangException.create(EErrorCode.payFailure);
        }
    }

    /**
     * 自费回调业务处理
     * @param userId 乘客id
     * @param tag 用户来源
     * @param payType 交易类型 0支付宝1微信
     * @param orderNo 订单号
     * @param tradeNo 交易凭证号
     * @param otherMoney 三方金额
     * @param personalOfficialBalance 个人额度
     * @param deptOfficialBalance 部门额度
     * @param drawFee 司机抽成费
     * @param totalFee 订单总费用
     * @param oaCOrderPersonal 自费叫车订单实体
     */
    private void callbackOaCOrderPersonal(
            Long userId,
            String tag,
            Integer payType,
            String orderNo,
            String tradeNo,
            BigDecimal otherMoney,
            BigDecimal personalOfficialBalance,
            BigDecimal deptOfficialBalance,
            BigDecimal drawFee,
            BigDecimal totalFee,
            OaCOrderPersonal oaCOrderPersonal){
        BigDecimal zero = new BigDecimal("0");
        Date date = new Date();
        // 支付宝
        if (payType.equals(0)){
            // 插入钱包记录
            iOaCUserPayService.insertOaCWalletRecord(userId, orderNo, otherMoney, zero, personalOfficialBalance, deptOfficialBalance, ERecordType.alipayDisbursement, tradeNo, date, tag, EIsTransaction.paySuccess);
            // 更新司机钱包
            iOaCUserPayService.updateDriverWallet(oaCOrderPersonal.getDriverId(), userId, tag, drawFee, orderNo, EDRecordType.aliPayIncome, tradeNo);
            // 更新订单
            iOaCUserPayService.updateOaCOrderPersonal(oaCOrderPersonal, totalFee, date, userId, EPayType.alipay);
        }
        // 微信
        else {
            // 插入钱包记录
            iOaCUserPayService.insertOaCWalletRecord(userId, orderNo, otherMoney, zero, personalOfficialBalance, deptOfficialBalance, ERecordType.weChatDisbursement, tradeNo, date, tag, EIsTransaction.paySuccess);
            // 更新司机钱包
            iOaCUserPayService.updateDriverWallet(oaCOrderPersonal.getDriverId(), userId, tag, drawFee, orderNo, EDRecordType.weChatIncome, tradeNo);
            // 更新订单
            iOaCUserPayService.updateOaCOrderPersonal(oaCOrderPersonal, totalFee, date, userId, EPayType.weChat);
        }
    }

    /**
     * 审批回调业务处理
     * @param userId 乘客id
     * @param tag 用户来源
     * @param payType 交易类型 0支付宝1微信
     * @param orderNo 订单号
     * @param tradeNo 交易凭证号
     * @param otherMoney 三方金额
     * @param personalOfficialBalance 个人额度
     * @param deptOfficialBalance 部门额度
     * @param drawFee 司机抽成费
     * @param totalFee 订单总费用
     * @param oaCOrderApprovalOfficial 审批订单实体
     */
    private void callbackOaCOrderApprovalOfficial(
            Long userId,
            String tag,
            Integer payType,
            String orderNo,
            String tradeNo,
            BigDecimal otherMoney,
            BigDecimal personalOfficialBalance,
            BigDecimal deptOfficialBalance,
            BigDecimal drawFee,
            BigDecimal totalFee,
            OaCOrderApprovalOfficial oaCOrderApprovalOfficial){
        BigDecimal zero = new BigDecimal("0");
        Date date = new Date();
        // 代付
        OaCOrderPersonal personal = null;
        if (EInvitationType.personal.getValue().equals(oaCOrderApprovalOfficial.getInvitationType()) &&
                EInvitationPayType.invitePeoplePay.getValue().equals(oaCOrderApprovalOfficial.getInvitationPayType())){
            // 邀约拼车流水号
            String carpoolSerialNo = oaCOrderApprovalOfficial.getCarpoolSerialNo();
            // 被邀约人订单
            personal = iOaCCostDetailsService.getInvitationOaCOrderPersonal(tag, carpoolSerialNo);
            if (CheckUtil.objIsNotEmpty(personal)){
                drawFee = drawFee.add(iOaCCostDetailsService.bigDecimalIsNull(personal.getDrawFee()));
            }
        }
        // 支付宝
        if (payType.equals(0)){
            // 插入钱包记录
            iOaCUserPayService.insertOaCWalletRecord(userId, orderNo, otherMoney, zero, personalOfficialBalance, deptOfficialBalance, ERecordType.alipayDisbursement, tradeNo, date, tag, EIsTransaction.paySuccess);
            // 更新司机钱包
            iOaCUserPayService.updateDriverWallet(oaCOrderApprovalOfficial.getDriverId(), userId, tag, drawFee, orderNo, EDRecordType.aliPayIncome, tradeNo);
            // 更新订单
            // 被邀人更新订单
            if (CheckUtil.objIsNotEmpty(personal)){
                iOaCUserPayService.updateOaCOrderPersonal(personal, iOaCCostDetailsService.bigDecimalIsNull(personal.getTotalFee()), date, userId, EPayType.alipay);
            }
            iOaCUserPayService.updateOaCOrderApprovalOfficial(oaCOrderApprovalOfficial, totalFee, date, userId, EPayType.alipay);
        }
        // 微信
        else {
            // 插入钱包记录
            iOaCUserPayService.insertOaCWalletRecord(userId, orderNo, otherMoney, zero, personalOfficialBalance, deptOfficialBalance, ERecordType.weChatDisbursement, tradeNo, date, tag, EIsTransaction.paySuccess);
            // 更新司机订单
            iOaCUserPayService.updateDriverWallet(oaCOrderApprovalOfficial.getDriverId(), userId, tag, drawFee, orderNo, EDRecordType.weChatIncome, tradeNo);
            // 更新订单
            // 被邀人更新订单
            if (CheckUtil.objIsNotEmpty(personal)){
                iOaCUserPayService.updateOaCOrderPersonal(personal, iOaCCostDetailsService.bigDecimalIsNull(personal.getTotalFee()), date, userId, EPayType.alipay);
            }
            iOaCUserPayService.updateOaCOrderApprovalOfficial(oaCOrderApprovalOfficial, totalFee, date, userId, EPayType.weChat);
        }
    }
}
